package org.wjk.pojo.entity;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import lombok.experimental.Accessors;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.AuthorityUtils;
import org.springframework.security.core.userdetails.UserDetails;

import java.util.Collection;
import java.util.List;

@Data
@Accessors(chain = true)
@TableName("sys_user")
public class SysUserEntity extends CommonBase implements UserDetails {
    private static final long serialVersionUID = 4663262792189622925L;
    @TableId(type = IdType.AUTO)
    private Integer id;
    private String username;
    private String password;
    private String userFace;
    private Integer empId;
    private Integer roleId;
    private Boolean isAccNonLocked;
    private Boolean isEnabled;
    private String recodeUser;
    private String modifiedUser;
    @TableField(exist = false)
    private List<String> permissions;

    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        if (permissions.isEmpty())
            return null;
        else
            return AuthorityUtils.createAuthorityList(permissions.toArray(new String[0]));
    }


    @Override
    public boolean isAccountNonExpired() {
        return true;
    }

    @Override
    public boolean isAccountNonLocked() {
        return this.isAccNonLocked;
    }

    @Override
    public boolean isCredentialsNonExpired() {
        return true;
    }

    @Override
    public boolean isEnabled() {
        return this.isEnabled;
    }
}
